int GreenPin =13;//定义绿灯引脚
int BluePin = 12;//定义蓝灯引脚
int RedPin = 11;//定义红灯引脚
int led_time = 500;
int color_time=3;
int random_pwm;
void setup() {
  pinMode(RedPin,OUTPUT);
  pinMode(GreenPin,OUTPUT);
  pinMode(BluePin,OUTPUT);
}
 
void loop() {
  random_color_light(led_time);
//  breath_red_light(color_time);
//  breath_green_light(color_time);
//  breath_blue_light(color_time);
//  breath_yellow_light(color_time);
//  breath_cyan_light(color_time);
//  breath_purple_light(color_time);
//  breath_white_light(color_time);
}
//RGB灯颜色随机
void random_color_light(int x){
  random_pwm=random(0,256);
  analogWrite(RedPin,random_pwm);
  random_pwm=random(0,256);
  analogWrite(GreenPin,random_pwm);
  random_pwm=random(0,256);
  analogWrite(BluePin,random_pwm);
  led_time = random(0,1000);
  delay(led_time);
}
//亮红灯
void breath_red_light(int x){
  for(int i=0;i<=255;i++){
    analogWrite(RedPin,i);
    delay(x);
  }
  for(int i=255;i>=0;i--){
    analogWrite(RedPin,i);
    delay(x);
  }
}
//亮绿灯
void breath_green_light(int x){
  for(int i=0;i<=255;i++){
    analogWrite(GreenPin,i);
    delay(x);
  }
  for(int i=255;i>=0;i--){
    analogWrite(GreenPin,i);
    delay(x);
  }
}
//亮蓝灯
void breath_blue_light(int x){
  for(int i=0;i<=255;i++){
    analogWrite(BluePin,i);
    delay(x);
  }
  for(int i=255;i>=0;i--){
    analogWrite(BluePin,i);
    delay(x);
  }
}
//亮黄灯
void breath_yellow_light(int x){
  for(int i=0;i<=255;i++){
    analogWrite(RedPin,i);
    analogWrite(GreenPin,i);
    delay(x);
  }
  for(int i=255;i>=0;i--){
    analogWrite(RedPin,i);
    analogWrite(GreenPin,i);
    delay(x);
  }
}
//亮青灯
void breath_cyan_light(int x){
  for(int i=0;i<=255;i++){
    analogWrite(GreenPin,i);
    analogWrite(BluePin,i);
    delay(x);
  }
  for(int i=255;i>=0;i--){
    analogWrite(GreenPin,i);
    analogWrite(BluePin,i);
    delay(x);
  }
}
//亮紫灯
void breath_purple_light(int x){
  for(int i=0;i<=255;i++){
    analogWrite(RedPin,i);
    analogWrite(BluePin,i);
    delay(x);
  }
  for(int i=255;i>=0;i--){
    analogWrite(RedPin,i);
    analogWrite(BluePin,i);
    delay(x);
  }
}
//亮白灯
void breath_white_light(int x){
  for(int i=0;i<=255;i++){
    analogWrite(RedPin,i);
    analogWrite(GreenPin,i);
    analogWrite(BluePin,i);
    delay(x);
  }
  for(int i=255;i>=0;i--){
    analogWrite(RedPin,i);
    analogWrite(GreenPin,i);
    analogWrite(BluePin,i);
    delay(x);
  }
}
